<?php namespace Common\Model;
use Hdphp\Model\Model;
class Cate extends Model{
	protected $table = 'category';
	protected $validate = array(
		array('cname','required','分类名称不能为空',3,3),
		array('cname','maxlen:15','分类名称不得超过15个字符',3,3)
	);
	//分类添加
	public function store(){
	    if($this->create()){
	    		$this->add();
			return TRUE;
	    }
		return FALSE;
	}
	//分类编辑
	public function edit(){
	    //先触发自动验证
	    if($this->create()){
	    		$this->save();
			return TRUE;
	    }
		return FALSE;
	}
	//删除分类
	public function del($cid){
		//pluck,拿到制定的字段
	    $pid = $this->where("cid={$cid}")->pluck('pid');
		$this->where("pid={$cid}")->save(array('pid'=>$pid));
		//删除当前分类
		$this->where(array('cid'=>$cid))->delete();
		return TRUE;
	}
}














 ?>